<%--
  Created by IntelliJ IDEA.
  User: dusy
  Date: 2017/11/29
  Time: 16:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <jsp:include page="../../head.jsp"/>
    <title>公告编辑</title>
    <script type="text/javascript">
        var formSetting = {
            title: "公告编辑",
            module: 'query',
            numCount: '3',
            columns: [
                {
                    name: "APPLIED_ROLES",
                    label: "适用角色",
                    type: "dropdown",
                    dropdownType: "ajax",
                    url: "/notice/appliedRoles",
                    op: "eq",
                    minLength: 0,
                }, {
                    name: "STATE",
                    label: "状态",
                    type: "dropdown",
                    data: [["草稿", "0"], ["生效", "1"]],
                    op: "eq",
                    minLength: 0
                }, {
                    name: "NEW_PUBLISH",
                    label: "是否当前发布版本",
                    type: "dropdown",
                    data: [["是", "0"], ["否", "1"]],
                    op: "eq",
                    minLength: 0
                }
            ],
            buttons: {
                custom: [
                    {
                        id: "publishBtn",
                        value: "发布",
                        click: function () {
                            var selectedRowId = $("#gridTable").getGridParam("selrow");
                            if (!selectedRowId) {
                                jw.alert("请选择要发布的公告！");
                            } else {
                                jw.confirm("确定发布", function () {
                                    $.ajax({
                                               url: "publish",
                                               type: "post",
                                               data: {"noticeId": selectedRowId},
                                               cache: false,
                                               dataType: "json",
                                               success: function (data) {
                                                   if (data.result) {
                                                       document.getElementById("queryButton").click();
                                                   }
                                                   jw.alert(data.msg);
                                               }
                                           });
                                }, function () {
                                    return;
                                })
                            }
                        }
                    }, {
                        id: "newBtn",
                        value: "新增",
                        click: function () {
                            $.ajax({
                                       url: "dealBeforeEdit",
                                       type: "post",
                                       cache: false,
                                       dataType: "json",
                                       success: function (data) {
                                           if (data) {
                                               window.location.href =
                                                   "../views/yxtPc/pages/addNotice.html?noticeId="
                                                   + data.data + "&noticeType=new";
                                           }
                                       }
                                   });
                        }
                    }, {
                        id: "updateBtn",
                        value: "修改",
                        click: function () {
                            var selectedRowId = $("#gridTable").getGridParam("selrow");
                            if (!selectedRowId) {
                                jw.alert("请选择要修改的公告！");
                            } else {
                                $.ajax({
                                           url: "dealBeforeEdit",
                                           type: "post",
                                           data: {"noticeId": selectedRowId},
                                           cache: false,
                                           dataType: "json",
                                           success: function (data) {
                                               if (data.result == true) {
                                                   window.location.href =
                                                       "../views/yxtPc/pages/addNotice.html?noticeId="
                                                       + selectedRowId + "&noticeType=update";
                                               } else {
                                                   jw.alert(data.msg)
                                               }
                                           }
                                       });
                            }
                        }
                    }, {
                        id: "delBtn",
                        value: "删除",
                        click: function () {
                            var selectedRowId = $("#gridTable").getGridParam("selrow");
                            if (!selectedRowId) {
                                jw.alert("请选择要删除的公告！");
                            } else {
                                jw.confirm("确定要删除？", function () {
                                    $.ajax({
                                               url: "deleteNotice",
                                               type: "post",
                                               data: {"noticeId": selectedRowId},
                                               cache: false,
                                               dataType: "json",
                                               success: function (data) {
                                                   if (data.result) {
                                                       location.reload();
                                                   } else {
                                                       jw.alert(data.msg);
                                                   }
                                               }
                                           });
                                }, function () {
                                    return;
                                });
                            }
                        }
                    }
                ]
            },
            grid: {
                id: "gridTable",
                title: "查询结果",
                url: "noticeList?edit=true",
                dataType: "application/json",
                rownumbers: true,
                colModel: [{
                    name: "id",
                    hidden: true
                }, {
                    index: "APPLIED_ROLES",
                    name: "appliedRoles",
                    label: "适用角色"
                }, {
                    index: "CREATE_TIME",
                    name: "createTime",
                    label: "创建时间"
                }, {
                    index: "U_NAME",
                    name: "creator",
                    label: "创建人"
                }, {
                    index: "STATE",
                    name: "state",
                    label: "状态",
                    formatter: function (cellValue) {
                        if (cellValue == '0') {
                            return '草稿';
                        } else if (cellValue == '1') {
                            return '生效';
                        }
                    }
                }, {
                    label: "是否当前发布版本",
                    name: "newPublish",
                    index: "NEW_PUBLISH",
                    formatter: function (cellValue) {
                        if (cellValue == '0') {
                            return '是';
                        } else if (cellValue == '1') {
                            return '否';
                        }
                    }
                }, {
                    lable: "备注",
                    name: "remark",
                    index: "REMARK"
                }]
            }

        };
        $(document).ready(function () {
            $("#dataTable").mrdForm(formSetting);
        });
    </script>
</head>
<body>
<div id="dataTable">
</div>
</body>
</html>

